top_builddir = ../..
srcdir = @srcdir@
top_srcdir = @top_srcdir@
include ../../Makefile.common

all: gfx.$(SLEXT)
static: SWF$(A) gfx$(A)
exe: mypython$(E) swfpython$(E) testmem$(E)

primitives.$(O): primitives.c primitives.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c primitives.c -o primitives.$(O)
tagmap.$(O): tagmap.c tagmap.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c tagmap.c -o tagmap.$(O)
taglist.$(O): taglist.c taglist.h tagmap.h tag.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c taglist.c -o taglist.$(O)
tag.$(O): tag.c tag.h tagmap.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c tag.c -o tag.$(O)
tags.$(O): tags.c tags.h tagmap.h tag.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c tags.c -o tags.$(O)
image.$(O): image.c image.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c image.c -o image.$(O)
action.$(O): action.c action.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c action.c -o action.$(O)
pyutils.$(O): pyutils.c pyutils.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c pyutils.c -o pyutils.$(O)
gfx.$(O): gfx.c 
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c gfx.c -o gfx.$(O)

SWF.$(O): SWF.c pyutils.h primitives.h taglist.h
	$(C) -Wall -Wno-unused -fPIC $(PYTHON_INCLUDES) -c SWF.c -o SWF.$(O)

SWF_OBJS=SWF.$(O) taglist.$(O) tag.$(O) image.$(O) tags.$(O) tagmap.$(O) action.$(O) primitives.$(O) pyutils.$(O) 
SWF_DEPS=../librfxswf$(A) ../libbase$(A)
SWF.$(SLEXT): $(SWF_OBJS) $(SWF_DEPS) Makefile
	$(L) -g $(SHARED) $(SWF_OBJS) $(SWF_DEPS) -o SWF.$(SLEXT) $(PYTHON_LIB) $(LIBS)
SWF$(A): $(SWF_OBJS) $(SWF_DEPS) Makefile
	$(AR) cru SWF$(A) $(SWF_OBJS) $(SWF_DEPS)
	$(RANLIB) SWF$(A)

GFX_DEPS=../libgfxpdf$(A) ../libgfxswf$(A)  ../librfxswf$(A) ../libgfx$(A) ../libocr$(A) ../libbase$(A) 
gfx.$(SLEXT): gfx.$(O) $(GFX_DEPS) Makefile
	$(L) -g $(SHARED) gfx.$(O) -o gfx.$(SLEXT) $(GFX_DEPS) $(PYTHON_LIB) $(LIBS) $(CXXLIBS)
gfx$(A): gfx.$(O) $(GFX_DEPS) Makefile
	mkdir -p tmp 
	ar cru gfx$(A) gfx.$(O)
	for file in $(GFX_DEPS);do rm -f tmp/*;cd tmp;ar x ../$$file || cp ../$$file .;cd ..;$(AR) q gfx$(A) tmp/*.$(O) || break;done
	$(RANLIB) gfx$(A)

#TODO:
install:

# for debugging:
mypython$(E): mypython.c Makefile
	$(L) -Wno-redundant-decls -g $(PYTHON_INCLUDES) mypython.c -o mypython$(E) $(PYTHON_LIB)
swfpython$(E): swfpython.c Makefile primitives.$(O) tagmap.$(O) taglist.$(O) tag.$(O) tags.$(O) action.$(O) pyutils.$(O) SWF.$(O)
	$(L) -Wno-redundant-decls -g $(PYTHON_INCLUDES) swfpython.c -o swfpython$(E) $(PYTHON_LIB) ../librfxswf$(A) ../png.$(O) $(LIBS)
testmem$(E): testmem.c Makefile
	$(L) $(PYTHON_INCLUDES) testmem.c -o testmem$(E) $(PYTHON_LIB) $(LIBS)

test: test6

test1: SWF.$(SLEXT)
	./test_create.py
	swfdump -p tmp/test.swf
test2: SWF.$(SLEXT)
	./test_combine.py
	swfdump -u -p tmp/combined.swf
test3: SWF.$(SLEXT)
	./test_simple.py
test4: SWF.$(SLEXT)
	./test_movie.py
	swfdump -u -p tmp/test.swf
test5: SWF.$(SLEXT)
	./test_image.py
	swfdump -u -p tmp/test.swf
test6: SWF.$(SLEXT)
	./test_sprite.py
clean:
	rm -f *.o *.obj *.so mypython swfpython

.PHONY: test test1 test2 static all exe
